<?php
namespace app\home\controller;

use app\common\model\HelpToRich;
use app\common\component\help_to_rich\HelpToRichService;

class ScalpingRich extends ControllerBase {
	public function _initialize() {
		$this -> checkLogin();
	}

	public function index() {
		(new HelpToRichService()) -> overtime();

		$helpToRichs = HelpToRich::alias('h_t_r')
			-> join('league_help_get_rich h_g_r', 'h_g_r.help_get_rich_id = h_t_r.help_get_rich_id')
			-> join('league_user u', 'h_g_r.user_id = u.user_id')
			-> field(
				'h_t_r.help_to_rich_id, h_t_r.help_get_rich_id, h_t_r.user_id h_t_r_user_id, h_t_r.order_id, h_t_r.price, h_t_r.create_time, h_t_r.begin_time, h_t_r.over_time, h_t_r.status, ' .
				'h_g_r.user_id h_g_r_user_id, ' .
				'u.username, u.realname, u.phone, u.bank_code'
			)
			-> where('h_t_r.user_id', \think\Session::get('user_id'))
			-> order('h_t_r.status ASC, h_g_r.help_to_rich_id DESC')
			-> paginate(10);

		$this -> view -> assign('helpToRichs', $helpToRichs);

        return $this -> view -> fetch();
	}

	public function confirmHelpToRich() {
		$post = $this -> request -> post();
		if($this -> validate($post, ['help_to_rich_id' => 'require|token']) !== true) {
			return json(['code' => -1, 'message' => '请勿重复提交!']);
		}

		return json((new HelpToRichService()) -> confirm($post['help_to_rich_id']));
	}
}
?>